﻿<script src="~/Scripts/jquery-easyui-extensions/selector/common/jeasyui.extensions.dialog.sealed.sample.js"></script>
<script src="~/Scripts/jquery-easyui-extensions/selector/common/jeasyui.extensions.selector.base.js"></script>
<link href="~/Scripts/jquery-easyui-extensions/selector/jeasyui.extensions.selector.css" rel="stylesheet" />
<script src="~/Scripts/jquery-easyui-extensions/selector/jeasyui.extensions.selector.accordionDblDatagrid.js"></script>
<link href="~/Scripts/jquery-easyui-extensions/base/jeasyui.extensions.base.css" rel="stylesheet" />
<script src="~/Scripts/jquery-easyui-extensions/base/jeasyui.extensions.base.loading.js"></script>
<div class="easyui-panel" data-options="fit:true,border:false,title:'本演示是简易版，不支持扩展的toolbar插件'" style="padding:20px;">
    选中项的Value：<input type="text" id="ID" name="ID" class="easyui-textbox" data-options="width:350,multiline:true,height:40" />
    <br /><br />
    选中项的Text：<input type="text" id="Name" name="Name" class="easyui-textbox" data-options="width:350,multiline:true,height:40" />
    <br />
    <br />
    <div style="border:1px solid red;width:500px;height:80px;text-align:center;padding:4px;line-height:40px;">
        <input type="radio" id="ss1" name="ss" checked="checked" value="true" /><label for="ss1">单选</label>
        <input type="radio" id="ss2" name="ss" value="false" /><label for="ss2">多选</label>
        <span style="color:red;font-weight:bold;">单/多选设置，只有通过以下按钮设置后才有效。</span>
        <br />
        <a id="btn2" class="easyui-linkbutton" data-options="iconCls:'icon-add'">清空已选信息并设置选择框的单/多选</a>
    </div>
    <br />
    <a id="btn1" class="easyui-linkbutton" data-options="iconCls:'icon-add'">打开accordionDblDatagrid选择框</a>
    当前选择框为<span id="spanSingle" style="color:red;font-weight:bold;">单选</span>
    <br /><br />
    <a class="easyui-linkbutton" href="javascript:window.location.href = '/Selector/AccordionDblDatagridDemo?full=true&data=remote'" data-options="iconCls:'icon-reload'">查看[带工具条、后台数据源分页的选择器]使用演示</a>
    <br /><br />
    <a class="easyui-linkbutton" href="javascript:window.location.href = '/Selector/AccordionDblDatagridDemo?full=false&data=local'" data-options="iconCls:'icon-reload'">查看[不带工具条、本地数据无分页的选择器]使用演示</a>
</div>

<script>
    $(function () {
        var single = true;

        $("#btn2").click(function () {
            $("#ID").textbox("setValue", "");
            $("#Name").textbox("setValue", "");
            single = $.string.toBoolean($("[name='ss']:checked").val());
            $("#spanSingle").text(single ? "单选" : "多选");
        });

        function fill(data) {
            if (!data) { return; }
            if ($.isArray(data)) {
                $("#ID").textbox("setValue", $.array.map(data, function (item) { return item.ID }).join(","));
                $("#Name").textbox("setValue", $.array.map(data, function (item) { return item.RealName }).join(","));
            } else {
                $("#ID").textbox("setValue", data.ID);
                $("#Name").textbox("setValue", data.RealName);
            }
        }

        $("#btn1").click(function () {

            var selected = $("#ID").textbox("getValue");

            var dia = $.easyui.showSelector.accordionDblDatagrid({
                title: "测试选择",
                width: 880,
                height: 450,
                onEnter: function (row) {
                    fill(row);
                },
                extToolbar: false,
                selected: selected,
                accordionOptions: {
                    width: 170,
                    panels: [
                        {
                            panelTitle: "按组织结构选择", type: "tree",
                            typeOptions: {
                                url: "/Selector/GetTreeJson",
                                // 查询人员的后台方法，需要识别参数：organId，因此这里通过 onSelectParamer 来指定参数的组装方式
                                onSelectParamer: function (node) { return { organId: node.id }; }
                            }
                        },
                        {
                            panelTitle: "按岗位选择", type: "tree",
                            typeOptions: {
                                url: "/Selector/GetTreeJson2",
                                // 查询人员的后台方法，需要识别参数：positionId，因此这里通过 onSelectParamer 来指定参数的组装方式
                                onSelectParamer: function (node) { return { positionId: node.id }; }
                            }
                        },
                        { panelTitle: "文本测试", type: "", typeOptions: "测试文本测试文本测试文本测试文本测试文本测试文本" },
                    ]
                },
                datagridOptions: {
                    singleSelect: single,
                    url: "/Selector/GetDataGridJson",
                    idField: 'ID',
                    columns: [[
                        { field: 'ID', title: '工号', width: 90 },
                        { field: 'RealName', title: '姓名', width: 90 }
                    ]],
                    queryParams: { first: true },
                    onBeforeLoad: function (params) { return !params.first; },
                    pagination: true,
                    //有分页的 DblDatagrid 选择框，一定要设置 selectedUrl 。
                    selectedUrl: "/Selector/GetSelectedDataGridJson"
                }
            });
        });

        top.window.$("#home-layout").layout("collapse", "west").layout("collapse", "east");
    });
</script>